Conversation
|
Thanks for your pull request and interest in making D better, @gorsing! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#22327" |
39bf153 to
9ce3a33
Compare
|
Happy new year! I have some comments about each of the key changes, but please keep each PR focused on 1 issue. It's fine to bundle a handful of trivial changes or include a typo fix here and there of course, but especially keep the 3 categories of PRs separate:
Mixing such changes makes it harder to review and test, but especially in the past it made bisecting regressions harder, when for example a crucial 1-line change was buried in a diff of 100 lines of reformatting. |
|
Happy new year! Hi @dkorpel Bug fixes: Fixes for memset size in destructor and safety checks in reserve. I'll link the new PRs here once they are created." |
|
@gorsing thank you for the excellent opening summary. |
|
Thanks, @WalterBright I'm glad the summary was helpful. As discussed with @dkorpel, I've split this work into separate PRs (including #22344 and #22351) to make reviews easier. I'll go ahead and close this one now. |
Refactor
dmd.root.Array: Fix debug stomping logic, optimizetoString, and improve ergonomicsDescription:
This MR introduces several improvements to the
dmd.root.Arraystruct, focusing on memory safety in debug modes, better ergonomics for slice usage, and optimized string conversion.Key Changes:
1. Fix Memory Stomping Logic (Debug Mode)
memsetsize calculation: In the previous implementation, the destructor andreservefunction (underdebug (stomp)) passeddata.length(element count) tomemset, instead ofdata.length * T.sizeof(byte count). This meant that for types larger than 1 byte, only a fraction of the memory was being "stomped" (overwritten with0xFF), potentially hiding use-after-free bugs.data.ptr != &smallarray[0]) in thereservedebug logic to ensure we do not attempt tomemsetorfreethe internal inline storage (Small Array Optimization) during resizing or destruction.2. Improve Ergonomics
alias opSlice this: TheArraystruct now includesalias opSlice this;.Array!Tto implicitly convert toT[]. It can now be passed directly to functions expecting a slice or a standard D range (e.g.,foreachloops,std.algorithm) without explicitly calling.dataor[].**3. Refactor
toString**,) and correctly calculates buffer sizes, replacing the previous complex pointer arithmetic.4. Minor Cleanups